async function fun() {
    const res = await axios({
        url: '/dashboard',
    })
    console.log(res);
    initoverview(res.data.overview)
    inityear(res.data.year)
    initpie(res.data.salaryData)
    initsalary(res.data.groupData)
    initMapChart(res.data.provinceData)
    initgender(res.data.salaryData)
}
fun()
function initoverview(obj) {
    for (const key in obj) {
        document.querySelector(`[name=${key}]`).innerHTML = obj[key]
    }
}
//折线图
function inityear(year) {
    // 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.getElementById('line'));
    // 指定图表的配置项和数据
    const option = {
        title: {
            text: '2023黑马97期',
            top: 10,
            left: 10,
        },
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: year.map(item => item.month),
            axisLine: {
                lineStyle: {
                    type: 'dashed',
                    color: '#d5d5d5'
                }
            }
        },
        yAxis: {
            type: 'value',
            splitLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        series: [
            {
                data: year.map(item => item.salary),
                type: 'line',
                symbolSize: 10,
                smooth: true,
                lineStyle: {
                    color: 'blue',
                    width: 6
                },
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [
                            {
                                offset: 0,
                                color: 'blue' // 0% 处的颜色
                            },
                            {
                                offset: 1,
                                color: '#fff' // 100% 处的颜色
                            }
                        ],
                        global: false // 缺省为 false
                    }
                }
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
//饼图
function initpie(salaryData) {
    // 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.getElementById('salary'));
    // 指定图表的配置项和数据
    const option = {
        title: {
            text: '班级薪资分布',
            top: 20,
            left: 10,
        },
        color: ['#fda224', '#5097ff', '#3abcfa', '#34d59b'],
        tooltip: {
            trigger: 'item'
        },
        legend: {
            bottom: '5%',
            left: 'center'
        },
        series: [
            {
                name: '班级薪资分布',
                type: 'pie',
                radius: ['50%', '65%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                },
                label: {
                    show: false,
                    position: 'center'
                },
                labelLine: {
                    show: false
                },
                data: salaryData.map(item => ({ value: item.g_count + item.b_count, name: item.label })),
            }
        ]
    };



    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
//期望薪资
function initsalary(groupData) {
    // 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.getElementById('lines'));
    // 指定图表的配置项和数据
    const option = {
        xAxis: {
            type: 'category',
            data: groupData[1].map(item => item.name),
            axisLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        yAxis: {
            type: 'value',
            splitLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        tooltip: {},
        series: [
            {
                name: '期望薪资',
                data: groupData[1].map(item => item.hope_salary),
                type: 'bar',
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#37d49c' },
                        { offset: 1, color: '#caf3e4' }
                    ])
                }
            },
            {
                name: '就业薪资',
                data: groupData[1].map(item => item.salary),
                type: 'bar',
                itemStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: '#4a9fee' },
                        { offset: 1, color: '#d4e8fa' }
                    ])
                }
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    //排他事件
    document.querySelector('#btns').addEventListener('click', function (e) {
        if (e.target.tagName == 'BUTTON') {
            document.querySelector('.btn-blue').classList.remove('btn-blue');
            e.target.classList.add('btn-blue')
            const id = e.target.innerText
            // console.log(id);
            option.xAxis.data = groupData[id].map(item => item.name)
            option.series[0].data = groupData[id].map(item => item.hope_salary)
            option.series[1].data = groupData[id].map(item => item.salary)
        }
        myChart.setOption(option);
    })
}
//地图
const initMapChart = (provinceData) => {
    const myEchart = echarts.init(document.querySelector('#map'))
    const dataList = [
        { name: '南海诸岛', value: 0 },
        { name: '北京', value: 0 },
        { name: '天津', value: 0 },
        { name: '上海', value: 0 },
        { name: '重庆', value: 0 },
        { name: '河北', value: 0 },
        { name: '河南', value: 0 },
        { name: '云南', value: 0 },
        { name: '辽宁', value: 0 },
        { name: '黑龙江', value: 0 },
        { name: '湖南', value: 0 },
        { name: '安徽', value: 0 },
        { name: '山东', value: 0 },
        { name: '新疆', value: 0 },
        { name: '江苏', value: 0 },
        { name: '浙江', value: 0 },
        { name: '江西', value: 0 },
        { name: '湖北', value: 0 },
        { name: '广西', value: 0 },
        { name: '甘肃', value: 0 },
        { name: '山西', value: 0 },
        { name: '内蒙古', value: 0 },
        { name: '陕西', value: 0 },
        { name: '吉林', value: 0 },
        { name: '福建', value: 0 },
        { name: '贵州', value: 0 },
        { name: '广东', value: 0 },
        { name: '青海', value: 0 },
        { name: '西藏', value: 0 },
        { name: '四川', value: 0 },
        { name: '宁夏', value: 0 },
        { name: '海南', value: 0 },
        { name: '台湾', value: 0 },
        { name: '香港', value: 0 },
        { name: '澳门', value: 0 },
    ]
    let option = {
        title: {
            text: '籍贯分布',
            top: 10,
            left: 10,
            textStyle: {
                fontSize: 16,
            },
        },
        tooltip: {
            trigger: 'item',
            formatter: '{b}: {c} 位学员',
            borderColor: 'transparent',
            backgroundColor: 'rgba(0,0,0,0.5)',
            textStyle: {
                color: '#fff',
            },
        },
        visualMap: {
            min: 0,
            max: 6,
            left: 'left',
            bottom: '20',
            text: ['6', '0'],
            inRange: {
                color: ['#ffffff', '#0075F0'],
            },
            show: true,
            left: 40,
        },
        geo: {
            map: 'china',
            roam: false,
            zoom: 1.0,
            label: {
                normal: {
                    show: true,
                    fontSize: '10',
                    color: 'rgba(0,0,0,0.7)',
                },
            },
            itemStyle: {
                normal: {
                    borderColor: 'rgba(0, 0, 0, 0.2)',
                    color: '#e0ffff',
                },
                emphasis: {
                    areaColor: '#34D39A',
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
            },
        },
        series: [
            {
                name: '籍贯分布',
                type: 'map',
                geoIndex: 0,
                data: dataList,
            },
        ],
    }
    provinceData.forEach(item => {
        const obj = dataList.find(v => item.name.indexOf(v.name) != -1)
        obj.value = item.value
    });
    myEchart.setOption(option)
}

//男女薪资
function initgender(salary) {
    const myEchart = echarts.init(document.querySelector('#gender'))
    const colorList = ['#fda224', '#5097ff', '#3abcfa', '#34d39a']
    const option = {
        color: colorList,
        tooltip: {
            trigger: 'item'
        },
        title: [
            {
                text: '男女薪资分布',
                left: '2%',
                top: '2%'
            },
            {
                text: '男',
                left: 'center',
                top: '45%'
            },
            {
                text: '女',
                left: 'center',
                top: '90%'
            }
        ],
        series: [
            {
                type: 'pie',
                radius: ['20%', '30%'],
                center: ['50%', '70%'],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                },
                data: salary.map(item => ({ name: item.label, value: item.g_count }))
            },
            {
                type: 'pie',
                radius: ['20%', '30%'],
                center: ['50%', '25%'],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                },
                data: salary.map(item => ({ name: item.label, value: item.b_count }))
            },
        ]
    };
    myEchart.setOption(option)
}

